from appium.webdriver.common.appiumby import AppiumBy
from AppTest.page.base_page import BasePage


class InductionPage(BasePage):

    # 手动添加
    __BUTTON_ADDEMPLOYEE = (AppiumBy.XPATH, "//android.view.View[@content-desc='手动添加']")
    __INPUT_NAME = (AppiumBy.XPATH, "//android.view.View[@content-desc='姓名']/following-sibling::*[1]")
    __INPUT_PHONENUMBER = (
        AppiumBy.XPATH, "//android.view.View[@content-desc='手机']/following-sibling::*[1]/child::*[2]")
    __INPUT_SEX = (AppiumBy.XPATH, "//android.view.View[@content-desc='性别']/following-sibling::*[1]")
    __INPUT_EMPLOYEETYPE = (AppiumBy.XPATH, "//android.view.View[@content-desc='员工类型']/following-sibling::*[1]")
    __INPUT_EMPLOYEEMENTDATE = (AppiumBy.XPATH, "//android.view.View[@content-desc='入职日期']/following-sibling::*[1]")
    __INPUT_DEPARTMENT = (AppiumBy.XPATH, "//android.view.View[@content-desc='部门']/following::*[1]")
    __BUTTON_SAVE = (AppiumBy.XPATH, "//android.widget.Button[@content-desc='保存']")
    __BUTTON_ADDANDSAVE = (AppiumBy.XPATH, "//android.widget.Button[@content-desc='保存并继续添加']")

    # 入职审批
    __BUTTON_EMPDETAIL = (
        AppiumBy.XPATH, "//android.view.View[@content-desc='手动添加']/preceding-sibling::*[2]/child::*/child::*[2]")
    __BUTTON_DINDUCTION = (AppiumBy.XPATH, "//android.widget.Button[@content-desc='确认入职']")
    __BUTTON_PROBATION = (AppiumBy.XPATH, "//android.view.View[@content-desc='试用期']/following::*[1]")

    # 手动添加
    def to_addemp(self):
        self.do_click(self.__BUTTON_ADDEMPLOYEE)

    def add_name(self, name):
        self.do_click(self.__INPUT_NAME)
        self.do_send_keys(self.__INPUT_NAME, name)

    def add_phonenumber(self, phonenumber):
        self.do_click(self.__INPUT_PHONENUMBER)
        self.do_send_keys(self.__INPUT_PHONENUMBER, phonenumber)

    def add_sex(self, sex):
        self.do_click(self.__INPUT_SEX)
        by = (AppiumBy.XPATH, f"//android.view.View[@content-desc='{sex}']")
        self.do_click(by)

    def add_emptype(self, type):
        self.do_click(self.__INPUT_EMPLOYEETYPE)
        by = (AppiumBy.XPATH, f"//android.view.View[@content-desc='{type}']")
        self.do_click(by)

    def add_date(self,):
        self.do_click(self.__INPUT_EMPLOYEEMENTDATE)
        by = (AppiumBy.XPATH, "//android.widget.Button[@content-desc='确定']")
        self.do_click(by)

    def add_department(self, department):
        self.do_click(self.__INPUT_DEPARTMENT)
        by = (AppiumBy.XPATH, "//*[@text='选择部门']/parent::*/parent::*/parent::*/parent::*/parent::*/parent::*/child"
                              "::*[2]/child::*")
        self.do_find(by).click()
        by = (AppiumBy.XPATH, "//*[@text='确定']")
        self.do_click(by)

    def add_save(self):
        self.do_click(self.__BUTTON_SAVE)

    def add_saveadd(self):
        self.do_click(self.__BUTTON_ADDANDSAVE)

    # 入职审批
    def to_empdetail(self):
        self.do_click(self.__BUTTON_EMPDETAIL)

    def to_dinduction(self):
        self.do_click(self.__BUTTON_DINDUCTION)

    def set_probation(self, mounth):
        self.do_click(self.__BUTTON_PROBATION)
        by = (AppiumBy.XPATH, f"//android.view.View[@content-desc='{mounth}']")
        self.do_click(by)



